/*
 * String.prototype.charAt(index) 获取指定索引处的单个字符
 * String.prototype.substring(begin[,end]) 从字符串中截取子串
 * String.prototype.slice(begin[,end]) 从字符串中截取子串
 * String.prototype.split( [separator [ , limit ]] ) 拆分字符串为字符串数组
 * String.prototype.concat( str1 , [, ...strN] ) 连接字符串并返回新字符串
 */

let str = '1001011' ;

let sum = 0 ;
for( let i = str.length - 1 , n = 0 ; i >= 0 ; i-- , n++ ){
    let ch = str.charAt( i ); // String.prototype.charAt(index)
    sum += ch * ( 2 ** n );
}
console.log( sum );

let s = 'https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/String' ;

console.log( '总串' , s );

const slash = '/' ;

let lastSlash = s.lastIndexOf( slash );

// 从字符串中截取 [ begin , s.length ) 之间的内容
let x = s.substring( lastSlash );
console.log( x );

// 获取 slash 首次出现的位置
let firstSlash = s.indexOf( slash );
let secondSlash = s.indexOf( slash , firstSlash + 1 );
let thirdSlash = s.indexOf( slash , secondSlash + 1 );

// 从字符串中截取 [ begin , end ) 之间的内容
let y = s.substring( secondSlash + 1 , thirdSlash );
console.log( y );

console.log( '- - - - - - - - - - - - - - - - - -' );

let p = s.slice( secondSlash + 1 ); // 仅指定起始位置
console.log( p );

console.log( secondSlash );
let q = s.slice( secondSlash + 1 , 29 ); // 指定开始位置和结束位置
console.log( q );

let t = s.slice( -21 , -6 ); // 截取 [ s.length - 21 , s.length - 6 ) 之间的内容
// let t = s.slice( s.length - 21 , s.length - 6 );
console.log( t );

console.log( '- - - - - - - - - - - - - - - - - -' );

let names = '朱亚红;马俊珍;郑娅婷;韩采采;何正甜' ;

let array = names.split( ';' );
console.log( array );
console.log( Array.isArray( array ) );

let first = '美丽的' ;
let second = '活泼的' ;
let third = '可爱的' ;

let fourth = '郭襄' ; 

// let fifth = fourth + '是个' + first + second + third + '小姑娘' ;
let fifth = fourth.concat( '是个' , first , second , third , '小姑娘' );
console.log( fifth );
